<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" label-width="98px" ref="queryForm" size="small"
             v-show="showSearch">
      <el-form-item label="请购单号" prop="nos">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入请购单号" v-model="queryParams.nos"/>
      </el-form-item>
      <el-form-item label="订单编号" prop="code">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入订单编号" v-model="queryParams.code"/>
      </el-form-item>
      <el-form-item label="下单日期" prop="ddDate">
        <el-date-picker clearable
                        v-model="queryParams.ddDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择下单日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="需求日期" prop="params.deliveryTime">
        <el-date-picker clearable
                        v-model="queryParams.params['deliveryTime']"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择需求日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple"
                   @click="handleExport" >导出
        </el-button>
      </el-form-item>
    </el-form>

    <el-table :data="dataList" :max-height="tableMaxHeight" @selection-change="handleSelectionChange"
              v-loading="loading"  @sort-change="handleSortChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column sortable align="center" label="请购单号" prop="nos" width="150"/>
      <el-table-column sortable align="center" label="请购来源" prop="source">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.please_buy_source" :value="scope.row.source"/>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="下单日期" prop="ddDate" width="150"/>
      <!--<el-table-column sortable align="center" label="请购日期" prop="createTime" width="150"/-->>
      <el-table-column sortable label="需求日期" align="center" prop="deliveryTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.subDate,'{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="订单编号" prop="code"  show-overflow-tooltip/>
      <el-table-column sortable align="center" label="业务员" prop="userName"/>
      <el-table-column sortable align="center" label="买方名称" prop="customerName"  show-overflow-tooltip/>
      <el-table-column align="center" label="附件" prop="attachment">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击下载附件" effect="dark" placement="left-start">
            <a :href="baseUrl + scope.row.params.attachment" style="color: #15B6FF;" target="_blank" download v-if="scope.row.params.attachment">附件</a>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column align="center" label="弃审原因" prop="reason"  show-overflow-tooltip/>
      <el-table-column sortable align="center" label="请购状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.please_buy_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="300">
        <template slot-scope="scope">
        <!-- 技术部弃审 -->
          <el-button v-if="scope.row.status==='0'" size="mini" type="text" icon="el-icon-close" @click="submitBohui(scope.row)">
            弃审
          </el-button>
          <el-button @click="handleBuyGoodsList(scope.row)" icon="el-icon-view"  size="mini" type="text">
            请购详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination :limit.sync="queryParams.pageSize" :page.sync="queryParams.pageNum" :total="total"
                @pagination="getList" v-show="total>0"/>

    <pleaseBuy-form-goods @ok="getList" ref="formGoods"></pleaseBuy-form-goods>
    <please-buy-goods-list @ok="getList" ref="pleaseBuyGoodsList"></please-buy-goods-list>
    <lvdoBohui-tech-form @ok="getList" ref="bohuiTechForm"></lvdoBohui-tech-form>
  </div>
</template>

<script>
import {deleteAction, downloadFile, getAction} from '@/api/manage'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {treeselect} from "@/api/system/dept";
import PleaseBuyFormGoods from "./prjForGoodsIn/PleaseBuyFormGoods";
import PleaseBuyGoodsList from "@/views/develop/pleaseBuy/prjForGoodsIn/PleaseBuyGoodsList.vue";
import LvdoBohuiForm from "@/views/develop/pleaseBuy/prjForGoodsIn/LvdoBohuiForm.vue";
import LvdoBohuiTechForm from "@/views/develop/pleaseBuy/prjForGoodsIn/LvdoBohuiTechForm.vue";


export default {
  name: "PleaseBuyOrderList",
  dicts: ['yes_no', 'fund_callback', 'fund_status', 'tax_status','please_buy_status','please_buy_source'],
  components: {
    LvdoBohuiTechForm,
    LvdoBohuiForm,
    PleaseBuyGoodsList,
    PleaseBuyFormGoods,
    Treeselect,
    /*PleaseBuyLookGoods,
    GoodsOrderinChose*/
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单基础信息管理表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        yearStr: null,
        pageNum: 1,
        pageSize: 20,
        name: null,
        code: null,
        nos: null,
        master: null,
        mainId: null,
        customName: null,
        companyName: null,
        contractDate: null,
        contractMoney: null,
        auditMoney: null,
        checkDate: null,
        checkState: null,
        ddDate: null,
        fundCallback: null,
        infomation: null,
        orderByColumn: "create_time",
        isAsc: "desc",
        params: {
          deliveryTime: null,
        },
      },
      url: {
        list: '/lvDo/lvDo/list',
        submitProjectScalaDo: '/projectBaseInfo/projectBaseInfo/submitProjectScalaDo',
        exportByPleaseBuyIds: '/goodsSaledo/goodsSaledo/exportByPleaseBuyIds',
      },
      tableMaxHeight: window.innerHeight - 320,
      // 部门树选项
      deptOptions: [],
      baseUrl: process.env.VUE_APP_BASE_API,
    };
  },
  created() {
    this.queryParams.status = this.$route.query.status;
    this.getList();
  },
  methods: {
    /** 排序触发事件 */
		handleSortChange(column, prop, order) {
		  this.queryParams.orderByColumn = column.prop;
		  this.queryParams.isAsc = column.order;
		  this.handleQuery();
		},
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleExport() {
      const ids = this.ids;
      this.queryParams.params["pleaseBuyIds"] = ids;
      downloadFile(this.url.exportByPleaseBuyIds, this.queryParams);
    },
    handleChoseOther(row) {
      this.$refs.formChoseOther.chose(row.id, "2");
    },
    submitProjectScalaDo(row) {
      getAction(this.url.submitProjectScalaDo, {id: row.id, status: "4"}).then(response => {
        this.getList();
        this.$modal.msgSuccess("提交成功!");
      }).catch(() => {
      });
    },
    lookGoods(row) {
      this.$refs.lookGoodsForm.handleUpdate(row);
    },
    fapiaoHX(row, type) {
      let that = this;
      that.$refs.InvoiceInfoListDialog.showAllInvoices(row);
    },
    handleAddFeeInfo(row) {
      let that = this;
      that.$refs.ProjectBaseInfoFormGoodsFee.handleUpdate(row);
    },
    handleAddInvoiceInfo(row) {
      let that = this;
      that.$refs.ProjectInvoiceInfoFormForPrj.handleAddNew(row);
    },
    handleUpdateDetail(row) {
      this.$refs.ProjectBaseInfoFormForPrj.handleUpdateDetail(row);
    },
    /** 查询项目基础信息管理列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleChoseGoods(row) {
      this.$refs.formGoods.handleUpdate(row);
    },
    handleBuyGoodsList(row) {
      this.$refs.pleaseBuyGoodsList.handleShow(row);
    },
    submitBohui(row) {
      this.$refs.bohuiTechForm.showTechBohui(row.id,"1");
    },

  }
};
</script>
